
<#include "/shared/style.ftl" />
<#include "/shared/javascript.ftl" />

<fieldset class="layui-elem-field layui-field-title" style="width: 45%;">
    <legend>添加用户</legend>
    <form class="layui-form" action="${baseUrlAdmin}/user/addAjax" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label">昵称</label>
            <div class="layui-input-block">
                <input type="text" name="name" required  lay-verify="required" placeholder="请输入昵称" autocomplete="off" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input type="text" name="email" required  lay-verify="required" placeholder="请输入邮箱" autocomplete="off" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
                <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">类型</label>
            <div class="layui-input-block">
                <select name="type" lay-verify="required">
                <#list types as type>
                    <option value="${type.value}">${type.text}</option>
                </#list>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <select name="status" lay-verify="required">
                    <#list statuses as status>
                        <option value="${status.value}">${status.text}</option>
                    </#list>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formSubmit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</fieldset>

<script type="text/javascript">
    layui.use(['form'], function () {
        var form = layui.form, layer = layui.layer;
        //监听提交
        form.on('submit(formSubmit)', function (e) {
            console.log(e.field);
            $.post('${baseUrlAdmin}/user/addAjax', e.field, function (data) {
                console.log(data);
                parent.layuiLayer.alert(data.message, { title: '提示' });
                if (data.code === 0) {
                    layuiManager.parentCloseTab(layuiTabConfig.userCreate.id);
                }
            });
            //layer.alert(JSON.stringify(e.field), { title: '最终的提交信息' });
            return false;
        });
    });
</script>
